﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BattingAverage
  {
  class Program
    {
    static void Main(string[] args)
      {
      int atBat = 0;
      int hits = 0;
      double battingAverage;
      New:

      getHits(ref hits); //call the satic that gets the hits from the user, sending the int hits and allowing it to change the value

      atBat = getAtBats(hits); //call the satic that gets the times at bats from the user, and the return is saved on the atBat int
			      
      battingAverage = getBatAvg(hits,atBat); //call the static that calculates the batting average, send the value of hits and times in base
      
      printAverage(atBat,hits,battingAverage); //call the static that prints the batting average, send the value of hits, times in base and batting average
      
			//This program is set to loop infinitiely after a batting average has been calculated, another can be calculated again.
      goto New;
      }

    static void getHits(ref int hits)
      {
      Console.WriteLine("Lets calculate a batting average, we need to provide the times at bat and the hits the player has\nPlease provide total hits");
			//this while will serve as a way that the user can only provide a Whole number
      while (!int.TryParse(Console.ReadLine(), out hits))
        Console.WriteLine("\nThe number is not a valud number, no decimals");    
      }

    static int getAtBats(int hits)
      {
      int atBat;
      Console.WriteLine("\nThanks, you have provided {0}, as the total hits\nNow please provide how many times the player has been at bat:", hits);
			//this while will serve as a way that the user can only provide a Whole number
      while (!int.TryParse(Console.ReadLine(), out atBat))
        Console.WriteLine("\nThe number is not a valud number, no decimals");
      return atBat;
      }

    static double getBatAvg(int hits, int atBat)
      {
      return (double)hits / (double)atBat;
      }

    static void printAvera0ge(int atBat, int hits, double battingAverage)
      {
      Console.WriteLine("\nThank You, you have provided {0}, as the total number at Bat for the player.\nThe batting Average is: {1:f3}\n\n", atBat, battingAverage);
      }
    }
  }